home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / AppleScript / Finder Scripting Toolkit 1.0 / fwin coercion osax / alis2fwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-20  |  1.3 KB  |  63 lines  |  [TEXT/MPS ]

  1. /*
  2.  
  3.         F W I N   C O E R C I O N   O S A X
  4.         
  5.         Version 1.0
  6.         Freeware by Daniel Ranson
  7.         
  8.         This osax performs coercions to the FinderWindow (fwin) record
  9.         type used by Finder events.
  10.         
  11.         There are actually three osax. This one converts aliases.
  12.  
  13. */
  14.  
  15. #include <Types.h>
  16. #include <Memory.h>
  17. #include <Aliases.h>
  18. #include <AppleEvents.h>
  19. #include <AERegistry.h>
  20.  
  21. struct FinderWindow{
  22.     long        windowType;
  23.     DescType    aliasType;
  24.     long        aliasLength;
  25.     AliasRecord    alias;
  26. };
  27.  
  28. typedef struct FinderWindow FinderWindow;
  29.  
  30. pascal OSErr ALIS2FWIN(    DescType    fromType,
  31.                         Ptr            dataPtr,
  32.                         Size        dataSize,
  33.                         DescType    toType,
  34.                         long        refCon,
  35.                         AEDesc        *result)
  36. {
  37. #pragma unused(fromType, toType, refCon)
  38.  
  39.     FinderWindow    **hFwin;
  40.     Size            sizH;
  41.     OSErr            err;
  42.     
  43.     /* Allocate the structure */
  44.     sizH = sizeof(FinderWindow) + dataSize - sizeof(AliasRecord);
  45.     hFwin = (FinderWindow**)NewHandle(sizH);
  46.     if (hFwin == 0) return errAECoercionFail;
  47.     
  48.     /* Fill in fields */
  49.     (**hFwin).windowType = 0;
  50.     (**hFwin).aliasType = typeAlias;
  51.     (**hFwin).aliasLength = dataSize;
  52.     BlockMove(dataPtr, &((**hFwin).alias), dataSize);
  53.     
  54.     /* Create the descriptor */
  55.     MoveHHi((Handle)hFwin);
  56.     HLock((Handle)hFwin);
  57.     err = AECreateDesc(typeFinderWindow, (Ptr)(*hFwin), sizH, result);
  58.     
  59.     /* Clean up */
  60.     DisposeHandle((Handle)hFwin);
  61.     return err;
  62. }
  63.